﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZFS.Library.Helper;
using ZFS.Model;
using ZFSData;
using ZFSInterface.User;

namespace ZFS.ServerBusiness
{
    public class WCF_UserManager : WCF_BaseManager<WCF_UserManager>, IUser
    {
        public tb_User AddEntity(tb_User entity)
        {
            var result = Server.AddEntityByUser(ZipTools.CompressionObject(entity));
            return ZipTools.DecompressionObject(result) as tb_User;
        }

        public bool DeleteEntity(tb_User entity)
        {
            bool result = Server.DeleteEntityByUser(ZipTools.CompressionObject(entity));
            return result;
        }

        public bool ExistEntity(tb_User entity)
        {
            bool result = Server.ExistEntityByUser(ZipTools.CompressionObject(entity));
            return result;
        }

        public List<View_UserAuthority> GetAuthority(string account)
        {
            var bytes = Server.GetAuthority(account);
            return ZipTools.DecompressionObject(bytes) as List<View_UserAuthority>;
        }

        public tb_User GetModelByAccount(string account)
        {
            var bytes = Server.GetModelByAccount(account);
            return ZipTools.DecompressionObject(bytes) as tb_User;
        }

        public List<tb_User> GetModels(tb_User search)
        {
            var bytes = Server.GetModelsByUser(ZipTools.CompressionObject(search));
            return ZipTools.DecompressionObject(bytes) as List<tb_User>;
        }

        public List<tb_User> GetPagingModels(int pageIndex, int pageSize, out int totalCount, tb_User search, bool Asc = false)
        {
            var bytes = Server.GetPagingModelsByUser(pageIndex, pageSize, ZipTools.CompressionObject(search), Asc, out totalCount);
            return ZipTools.DecompressionObject(bytes) as List<tb_User>;
        }

        /// <summary>
        /// 登录系统
        /// </summary>
        /// <param name="account">账户</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public tb_User Login(string account, string password)
        {
            byte[] bytes = Server.Login(account, password);
            if (bytes != null)
                return (tb_User)ZipTools.DecompressionObject(bytes);
            return null;
        }

        public void Logout(string account)
        {
            Server.Logout(account);
        }

        public bool UpdateEntity(tb_User entity)
        {
            return Server.UpdateEntityByUser(ZipTools.CompressionObject(entity));
        }
    }
}
